package com.common.base.base

import com.common.base.http.exceptions.CloudException
import com.common.base.http.main.CODE_INTERRUPTED_IO
import com.common.base.http.main.CODE_LOCAL_OFFLINE
import com.common.base.http.main.CODE_NO_HTTP
import com.common.base.http.main.CODE_NO_NETWORK
import com.common.base.http.main.CODE_SUCCESS
import com.common.base.http.main.CODE_TOKEN_INVALID
import com.common.base.http.main.CODE_UNKNOWN


/**
 * 公用
 */
open class BaseResponse(
     var code: Int? = null,
     var message: String? = null,
) {

    inline fun <reified T> FAIL(json: String){

    }
    fun isSuccess(): Boolean {
        return code == CODE_SUCCESS
    }

    fun isNoNetWork():Boolean{
        return code == CODE_UNKNOWN || code == CODE_NO_NETWORK || code == CODE_INTERRUPTED_IO || code == CODE_NO_HTTP
    }


    fun isTokenInValid(): Boolean {
        return code == CODE_TOKEN_INVALID
    }

   companion object{
       fun error(cloudException: CloudException): BaseResponse {
          return BaseResponse(cloudException.code,cloudException.message)
       }

       fun localOfflineFile():BaseResponse{
           return BaseResponse(code = CODE_LOCAL_OFFLINE, message = "Lack of offline logic")
       }
   }

}